package com.jzo2o.market.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 优惠卷状态枚举类
 * @author JIAN
 */
@Getter
@AllArgsConstructor
public enum CouponStatusEnum {
    NO_USE(1, "未使用"),
    USED(2, "已使用"),
    INVALID(3, "已失效"),
    VOIDED(4, "已作废");

    @EnumValue
    @JsonValue
    private int status;
    private String name;

    public static CouponStatusEnum statusOf(Integer status) {
        if (status == null) {
            return null;
        }

        for (CouponStatusEnum couponStatusEnum : CouponStatusEnum.values()) {
            if (couponStatusEnum.getStatus() == status) {
                return couponStatusEnum;
            }
        }

        // not found
        return null;
    }
}